package com.badibadi.adapter;

import java.util.ArrayList;
import java.util.List;

import net.tsz.afinal.FinalBitmap;

import com.android.volley.toolbox.NetworkImageView;
import com.badibadi.infos.BrowseAllPhoto_Model;
import com.badibadi.mytools.Constants;
import com.badibadi.mytools.VolleyTools;
import com.badibadi.uniclubber.R;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;

/**
 * 心情动态
 * 
 * @author Administrator
 * 
 */
public class GridViewSHUZHUAdapter extends BaseAdapter {

	private static final String TAG = "GridViewSHUZHUAdapter";
	// FinalBitmap finalBitmap;
	private String[] pic;
	private String[] picId;
	Context context;
	private DisplayImageOptions options;

	public GridViewSHUZHUAdapter(Context context, String[] picture,
			String[] picId) {
		pic = picture;
		this.picId = picId;
		this.context = context;
		options = new DisplayImageOptions.Builder()
				.showStubImage(R.drawable.ic_stub)
				.showImageForEmptyUri(R.drawable.noimage)
				.showImageOnFail(R.drawable.noimage).cacheInMemory()
				.cacheOnDisc().displayer(new RoundedBitmapDisplayer(0)).build();
		// finalBitmap=FinalBitmap.create(this.context);
		// finalBitmap.configLoadfailImage(R.drawable.noimage);
	}

	public GridViewSHUZHUAdapter(Context context, String[] picture) {
		pic = picture;
		this.context = context;
		options = new DisplayImageOptions.Builder()
				.showStubImage(R.drawable.ic_stub)
				.showImageForEmptyUri(R.drawable.noimage)
				.showImageOnFail(R.drawable.noimage).cacheInMemory()
				.cacheOnDisc().displayer(new RoundedBitmapDisplayer(0)).build();
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		if (pic.length <= 9) {
			return pic.length;
		}
		return 9;
	}

	public List<BrowseAllPhoto_Model> getBrowseAllPhoto_Model() {
		List<BrowseAllPhoto_Model> list = new ArrayList<BrowseAllPhoto_Model>();
		//    

		for (int i = 0; i < pic.length; i++) {
			try {
				BrowseAllPhoto_Model d = new BrowseAllPhoto_Model();
				d.setPath(pic[i]);
				d.setId(picId[i]);
//				   
				list.add(d);
			} catch (Exception e) {
				// TODO: handle exception
			}
		}

		return list;

	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	public String getItemIdtoString(int position) {
		return ("" + picId[position]);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		LayoutInflater ll = LayoutInflater.from(context);
		convertView = ll.inflate(R.layout.net_img1_img, null);
		ImageView iv = (ImageView) convertView.findViewById(R.id.img);

		// iv.setLayoutParams(new
		// LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT));
		try {
			ImageLoader.getInstance().displayImage(
					Constants.BadiDownImgUrl + "/" + pic[position]
							+ Constants.App9block, iv, options);

		} catch (Exception e) {
			// TODO: handle exception
		}

		// try {
		// VolleyTools.displayImageByNetworkImageView(context,
		// Constants.BadiDownImgUrl+"/"+pic[position], iv);
		// } catch (Exception e) {
		// // TODO: handle exception
		// }

		return convertView;
	}

}
